﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Dangnhap : System.Web.UI.Page
{
    XL xl = new XL();
    DADataContext da = new DADataContext();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Convert.ToString(Session["user"])))
        {
            user.Focus();
        }
        else
        {
            Response.Redirect("/Online/Admin/Default.aspx");
        }
    }
    protected void btn_Click(object sender, EventArgs e)
    {
        if (user.Text.Trim() == "" || pass.Text.Trim() == "")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), " ", "alert('Nhập đủ thông tin !')", true);
        }
        else
        {
            string paw = xl.mahoa(pass.Text.Trim());
            var kt = (from a in da.Accounts where a.Taikhoan == user.Text.Trim() && a.Matkhau == paw select a).Count();
            if (kt == 1)
            {
                Session["user"] = user.Text.Trim();
                Session.Timeout = 60;
                Response.Redirect("/Online/Admin/Default.aspx");
            }
            else
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), " ", "alert('Thông tin đăng nhập không đúng !')", true);
        }
    }

}
